/*
 * @Author: funlee
 * @Email: i@funlee.cn
 * @Date: 2019-07-03 09:30:11
 * @Description: Tab 导航的路由组件
 */
import React from "react";
import { HashRouter, Route, Redirect } from "react-router-dom";
import PropTypes from "prop-types";

function RouteMenu(props) {
    const { data } = props;
    let initUrl = data[0].path.split("/");
    initUrl.pop();
    const initPath = initUrl.join("/");
    return (
        <HashRouter>
            <Route key={`route--1`} path={initPath} exact render={() => <Redirect to={data[0].path} />} />
            {data.map((item, index) => (
                <Route path={item.path} component={item.component} key={`route-${index}`} />
            ))}
        </HashRouter>
    );
}

RouteMenu.propTypes = {
    data: PropTypes.arrayOf(
        PropTypes.shape({
            path: PropTypes.string.isRequired,
            component: PropTypes.any.isRequired // 功能完善后删除掉
            // component: PropTypes.element.isRequired
        })
    ).isRequired
};

export default RouteMenu;
